(semantic-mode 1)
;;;;;设定删除保存记录为200，可以方便以后无pp限恢复
(setq kill-ring-max 200)
;;;;;是用aspell程序作为Emacs的拼写检查成学
(setq-default ispell-program-name "aspell")


(global-set-key [(control ?\.)] 'ska-point-to-register)

;;(global-unset-key (kbd "C-k"))
;;;;;滚动页面时比较舒服，不要整页的滚动
;(setq scroll-step 1
;      scroll-margin 3
;      scroll-conservatively 10000)
;;;;;标记
(defun kill-the-whole-line()
  "rt"
  (interactive)
  (save-excursion
    (beginning-of-line)
    (kill-line)
    )
  )
(global-set-key [(control ?\,)] 'ska-jump-to-register)
(defun ska-point-to-register()
  "Store cursorposition _fast_ in a register. 
Use ska-jump-to-register to jump back to the stored 
position."
  (interactive)
  (setq zmacs-region-stays t)
  (point-to-register 8))
 
(defun ska-jump-to-register()
  "Switches between current cursorposition and position
that was stored with ska-point-to-register."
  (interactive)
  (setq zmacs-region-stays t)
  (let ((tmp (point-marker)))
    (jump-to-register 8)
    (set-register 8 tmp)))
(defun string<=(a b)
  (or (string< a b) (string= a b))
  )
(defun string>(a b)
  (not (string<= a b))
  )
(defun string>=(a b)
  (or (string> a b) (string= a b))
  )
(defun the_first_char_is_num(a)
  (let ((sa (substring a 0 1)))
    (and (string<= sa "9") (string>= sa "0"))
    )
  )
(defun filename()
  (file-name-nondirectory (buffer-file-name))
  )
(defun filename_non_extension()
  (file-name-sans-extension (filename))
  ;(substring (filename) 0 (string-match (regexp-quote ".") (filename)))
  )
;;minibuffer
(tool-bar-mode -1)
(ido-mode t)
;;热键设置
(global-set-key (kbd "C-k")
                (lambda ()
                  (interactive)
                  (kill-line)
                  )
                )
(defun plugin()
  (interactive)
  (cond
   ((eq system-type 'darwin) (find-file "~/.emacs.d/plugin/"))
   ((eq system-type 'gnu/linux) (find-file "~/workspace/dayixia/"))
   ((eq system-type 'windows-nt) (find-file "E:/ke/dayixia/"))
   )
  )
(defun homework()
  (interactive)
  (cond
   ((eq system-type 'darwin) (find-file "~/workspace/course/3.1/"))
   ((eq system-type 'gnu/linux) (find-file "~/workspace/dayixia/"))
   ((eq system-type 'windows-nt) (find-file "E:/ke/dayixia/"))
   )
  )
;; 回车缩进
(global-set-key "\C-m" 'newline-and-indent)
(global-set-key (kbd "C-<return>") 'newline-and-indent)
(define-key key-translation-map (kbd "C-<return>") (kbd "RET"))
(require 'my-mode-hooks)
(add-hook 'pascal-mode-hook 'my-pascal-mode-hook)
(add-hook 'c++-mode-hook 'my-c++-mode-hook)
(add-hook 'c-mode-hook 'my-c-mode-hook)
(add-to-list 'auto-mode-alist '("\\.cu\\'" . c++-mode))
;(add-hook 'python-mode-hook 'my-python-mode-hook)
;(add-hook 'elpy-mode-hook 'my-python-mode-hook)
(global-set-key [(control \')] 'replace-string)
(global-set-key [M-f6] 'speedbar)
(global-set-key [M-f5] 'delete-window)
(global-set-key [(control \;)] 'other-window)
(require 'smart-compile)
(global-set-key [f7] 'smart-compile)
(global-set-key [f9] 'gdb)
(global-set-key [M-f9] 'gdb-many-windows)
(global-set-key [M-f7] 'previous-error)
(global-set-key [M-f8] 'next-error)
;; (defun switch-oi-mode()
;;   (interactive)
;;   (if (and (boundp 'my-c++-oi-mode-hook) my-c++-oi-mode-hook)
;; 	  (progn ;;(remove-hook 'c++-mode-hook 'my-c++-oi-mode-hook)
;; 		(setq my-c++-oi-mode-hook nil) (my-c++-mode-hook))
;; 	(progn ;;(add-hook 'c++-mode-hook 'my-c++-oi-mode-hook)
;; 	  (setq my-c++-oi-mode-hook t) (my-c++-oi-mode-hook))
;; 	)
;; ;  (c++-mode)
;;   )
;(defun foo () (interactive) (insert "hello"))
;(defadvice foo (after foo-after activate) (insert " world!\n"))

;;;;;;;;; navigator/jump ;;;;;;;;
(defun marker-is-point-p (marker)
  "test if marker is current point"
  (and (eq (marker-buffer marker) (current-buffer))
       (= (marker-position marker) (point))))

(defun push-mark-maybe () 
  "push mark onto `global-mark-ring' if mark head or tail is not current location"
  (if (not global-mark-ring) (error "global-mark-ring empty")
    (unless (or (marker-is-point-p (car global-mark-ring))
                (marker-is-point-p (car (reverse global-mark-ring))))
      (push-mark))))


(defun backward-global-mark () 
  "use `pop-global-mark', pushing current point if not on ring."
  (interactive)
  (push-mark-maybe)
  (when (marker-is-point-p (car global-mark-ring))
    (call-interactively 'pop-global-mark))
  (call-interactively 'pop-global-mark))

(defun forward-global-mark ()
  "hack `pop-global-mark' to go in reverse, pushing current point if not on ring."
  (interactive)
  (push-mark-maybe)
  (setq global-mark-ring (nreverse global-mark-ring))
  (when (marker-is-point-p (car global-mark-ring))
    (call-interactively 'pop-global-mark))
  (call-interactively 'pop-global-mark)
  (setq global-mark-ring (nreverse global-mark-ring)))

;; (global-set-key (kbd "M-[") (quote backward-global-mark))
;; (global-set-key (kbd "M-]") (quote forward-global-mark))
